using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemMgr
{
    private static ItemMgr instance = null;
    public static ItemMgr Instance
    {
        get
        {
            if (instance == null)
                instance = new ItemMgr();
            return instance;
        }
    }

    private Dictionary<int, Item> _typeId2Item = new Dictionary<int, Item>();
    public Item GetItem(int typeId)
    {
        Item item;
        _typeId2Item.TryGetValue(typeId, out item);
        return item;
    }

    public int GetItemCount(int typeId)
    {
        var item = GetItem(typeId);
        if (item == null)
            return 0;
        return item.count;
    }

    public void SetItemCount(int typeId, int count)
    {
        var item = GetItem(typeId);
        if (item == null)
        {
            item = new Item();
            item.typeId = typeId;
            item.count = 0;
            _typeId2Item[typeId] = item;
        }
        item.count = count;

        Facade.Instance.SendEvent(GameEvent.Data.ItemChange, null);
    }
    public void IncrItemCount(int typeId, int vCount)
    {
        var count = GetItemCount(typeId);
        SetItemCount(typeId, count + vCount);
    }
}
